Skip to content

Wire up PostHog + Segment analytics on the docs site#194

Merged
dodeja merged 1 commit intomainfrom
add-posthog-analytics
Apr 11, 2026
Merged

Wire up PostHog + Segment analytics on the docs site#194
dodeja merged 1 commit intomainfrom
add-posthog-analytics

Conversation

@dodeja
Copy link
Copy Markdown
Contributor

@dodeja dodeja commented Apr 11, 2026

Summary

  • Adds the Mintlify PostHog and Segment integrations to docs/docs.json
  • PostHog — points apiHost at our existing Cloudflare Worker reverse proxy (api-posthog-worker.t49.workers.dev), matching how app.terminal49.com already ships events (see apps/tnt-ui/app/initializers/metrics.js). Same phc_l2ad… project key as the main app → docs traffic lands in the Production App+Website project (18843), alongside marketing + app events.
  • Segment — uses the same write key (QGH9…L7j2) that both terminal49.com (marketing, Next.js) and app.terminal49.com (Ember) already use, so docs events flow into the shared Segment source.

Why

Today PostHog sees 0 pageviews for terminal49.com/docs* in the last 30 days because the Mintlify site never loaded either snippet. The only /docs-adjacent traffic in PostHog is 23 legacy /api-docs* hits from the Ember marketing-site redirects, which isn't real docs traffic.

Wiring both up lets us study:

  • which docs pages are most/least visited
  • entry paths from marketing → docs → signup (unified in one Segment source)
  • docs behavior in whatever destinations Segment already fans out to (HubSpot, warehouse, etc.)
  • PostHog session recordings on the docs (enabled by default per Mintlify)

Why the PostHog proxy host (not us.i.posthog.com)

The Worker is a transparent proxy — it rewrites Host to us.i.posthog.com and forwards the request (src/index.js). It has no origin allowlist, so CORS is whatever PostHog upstream returns (permissive). Using the proxy bypasses adblockers — standard PostHog SOP — and keeps parity with app.terminal49.com.

Known limitation: Segment proxy parity

Mintlify's Segment integration config only accepts key — there's no way to point it at our cdn-segment-worker / api-segment-worker Workers. So docs Segment calls will hit cdn.segment.com / api.segment.io directly, and adblockers will drop some fraction. PostHog stays adblock-proof via the Worker either way. Not a blocker for landing this, but worth logging as future work.

Test plan

  • Merge and wait for Mintlify to rebuild
  • Open terminal49.com/docs in a private window, click around a few pages
  • In PostHog (project 18843), run a HogQL query filtered to $host = 'terminal49.com' AND $pathname LIKE '/docs%' — should see pageviews within a few minutes
  • In Segment, check the debugger for the shared source and confirm docs pageviews are flowing
  • Confirm no CSP / CORS errors in the docs browser console

🤖 Generated with Claude Code

Adds the Mintlify PostHog integration pointed at our existing
Cloudflare Worker reverse proxy (api-posthog-worker.t49.workers.dev),
matching how app.terminal49.com already ships events. Using the proxy
host bypasses adblockers and keeps docs traffic in the same Production
App+Website project (18843) as the main app and marketing site.

Currently PostHog sees ~0 events from terminal49.com/docs because the
Mintlify site never loaded the snippet.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api Ready Ready Preview, Comment Apr 11, 2026 11:08pm

Request Review

@mintlify
Copy link
Copy Markdown
Contributor

mintlify Bot commented Apr 11, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
terminal49 🟢 Ready View Preview Apr 11, 2026, 11:08 PM

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 11, 2026

Target branch is in the excluded branches list.

@dodeja dodeja merged commit aca1ddd into main Apr 11, 2026
11 checks passed
@dodeja dodeja changed the title Wire up PostHog analytics on the docs site Wire up PostHog + Segment analytics on the docs site Apr 11, 2026
dodeja added a commit that referenced this pull request Apr 11, 2026
Uses the same Segment write key that terminal49.com (marketing) and
app.terminal49.com (Ember app) already use, so docs events land in
the shared Segment source alongside marketing and app traffic.

Follow-up to #194, which wired up PostHog but landed before the
Segment commit could be reviewed.

Note: Mintlify's Segment integration has no apiHost/proxy option, so
docs events will hit cdn.segment.com / api.segment.io directly rather
than routing through the cdn-segment-worker / api-segment-worker
Cloudflare Workers that the Ember app and marketing site use. Not a
blocker for landing — a meaningful fraction of docs events will still
reach Segment; adblock-proofing can come later if Mintlify ships
apiHost support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dodeja added a commit that referenced this pull request Apr 11, 2026
Adds `docs/segment.js`, which Mintlify auto-includes on every page,
instead of using the built-in `integrations.segment` config. This
lets us route the CDN and ingest hosts through our Cloudflare Worker
reverse proxies — matching how app.terminal49.com and terminal49.com
already ship Segment — so adblockers don't drop events.

- CDN: cdn-segment-worker.t49.workers.dev -> cdn.segment.com
- API: api-segment-worker.t49.workers.dev/v1 -> api.segment.io/v1

Mintlify's built-in Segment integration only takes a write key and
loads directly from cdn.segment.com / api.segment.io, with no way to
point at a proxy host. Custom scripts (docs:
https://www.mintlify.com/docs/customize/custom-scripts) are the
documented escape hatch.

Also patches history.pushState / replaceState + listens to popstate
so analytics.page() fires on every SPA route change (Mintlify is a
SPA; analytics.js v1 doesn't auto-track client-side navigation).

Follow-up to #194 (PostHog) and replaces the earlier version of this
PR that used the built-in integration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dodeja added a commit that referenced this pull request Apr 12, 2026
* Add Segment analytics via custom script (proxied through CF Workers)

Adds `docs/segment.js`, which Mintlify auto-includes on every page,
instead of using the built-in `integrations.segment` config. This
lets us route the CDN and ingest hosts through our Cloudflare Worker
reverse proxies — matching how app.terminal49.com and terminal49.com
already ship Segment — so adblockers don't drop events.

- CDN: cdn-segment-worker.t49.workers.dev -> cdn.segment.com
- API: api-segment-worker.t49.workers.dev/v1 -> api.segment.io/v1

Mintlify's built-in Segment integration only takes a write key and
loads directly from cdn.segment.com / api.segment.io, with no way to
point at a proxy host. Custom scripts (docs:
https://www.mintlify.com/docs/customize/custom-scripts) are the
documented escape hatch.

Also patches history.pushState / replaceState + listens to popstate
so analytics.page() fires on every SPA route change (Mintlify is a
SPA; analytics.js v1 doesn't auto-track client-side navigation).

Follow-up to #194 (PostHog) and replaces the earlier version of this
PR that used the built-in integration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Update Segment snippet to official v5.2.1 with proxy hosts

Upgrades from the old v4.15.3 snippet (copied from the website repo)
to the current official v5.2.1 from:
https://www.twilio.com/docs/segment/connections/sources/catalog/libraries/website/javascript/quickstart

Key changes in v5.2.1:
- `register` and `screen` methods added to the stub list
- `data-global-segment-analytics-key` attribute on script tag
- Buffered page context (bpc) captures canonical URL, pathname,
  title, referrer when queuing calls (important for SPA correctness)
- Stale-reference guard when analytics is already initialized

Still routes through our Cloudflare Workers for adblocker bypass:
- CDN: cdn-segment-worker.t49.workers.dev
- API: api-segment-worker.t49.workers.dev/v1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant